function CalendarOverviewBody(locationContainer, activityContainer, repository) {
    this._activityContainer = activityContainer;
    this._locationContainer = locationContainer;
    this._repository = repository;
    this._calculateTotalDaysCallback = function(){};
    this._calculateActivityCallback = function(){};
    this._calculateLocationCallback = function(){};
}

CalendarOverviewBody.prototype = {
    _activityClassMap: ['work', 'non-work', 'sick', 'vacation', 'national-holiday'],

    _activityTextMap : {
        work: i18n('LABEL_ACTIVITY_WORK'),
        other: i18n('LABEL_ACTIVITY_OTHER'),
        sick: i18n('LABEL_ACTIVITY_SICK'),
        vacation: i18n('LABEL_ACTIVITY_PAID_TIME_OFF'),
        national: i18n('LABEL_ACTIVITY_NATIONAL_HOLIDAY')
    },

    update: function() {
        this._locationContainer.children().remove();
        this._activityContainer.children().remove();

        var totalDays = this._calculateTotalDaysCallback();

        var activitySummary = this._calculateActivityCallback();
        var locationSummary = this._calculateLocationCallback();

        var locationTable = this._createLocationTable(locationSummary, totalDays);
        var activityTable = this._createActivityTable(activitySummary, totalDays);

        this._locationContainer.append(locationTable);
        this._activityContainer.append(activityTable);
    },

    setCalculateTotalDaysCallback: function(callback){
        this._calculateTotalDaysCallback = callback;
    },

    setCalculateActivityCallback: function(callback){
        this._calculateActivityCallback = callback;
    },

    setCalculateLocationCallback: function(callback){
        this._calculateLocationCallback = callback;
    },

    _createLocationTable: function(locationSummary, totalDays) {
        var locationList = $('<div class="border"></div>');
        this._appendHeader(locationList, i18n('LABEL_SUMMARY_LOCATIONS_TITLE'));
        this._appendLocationRows(locationList, locationSummary.locations);
        this._appendTotalSummaryRow(locationList, locationSummary.total(), totalDays);
        return locationList;
    },

    _createActivityTable: function(activitySummary, totalDays) {
        var activityList = $('<div class="border"></div>');
        this._appendHeader(activityList, i18n('LABEL_SUMMARY_ACTIVITIES_TITLE'));
        this._appendActivityRows(activityList, activitySummary);
        this._appendTotalSummaryRow(activityList, activitySummary.total(), totalDays);
        return activityList;
    },
    
    _appendLocationRows: function(locationList, locations) {
        var listBody = $('<ul />').addClass('list');
        for (var location in locations) {
            var titleCell = this._createTitleCell(location);
            var valueCell = this._createValueCell(locations[location]);
            listBody.append(this._createRow(titleCell, valueCell));
        }
        listBody.find("li:odd").addClass("odd");
        locationList.append(listBody);
    },

    _appendActivityRows: function(activityList, activitySummary) {
        var listBody = $('<ul />').addClass('list');
        var me = this;
        activitySummary.eachActivity(function(activityName, activityCount, index) {
            var activityClass = me._activityClassMap[index];
            var titleCell = me._createTitleCell(me._activityTextMap[activityName], activityClass);
            var valueCell = me._createValueCell(activityCount);
            listBody.append(me._createRow(titleCell, valueCell));
        });
        listBody.find("li:odd").addClass("odd");
        activityList.append(listBody);
    },

    _appendTotalSummaryRow: function(locationList, totalValue, totalDays) {
        var footer = $('<ul class="footer" />');
        var titleCell = this._createTitleCell(i18n('LABEL_SUMMARY_TOTAL'));
        var valueCell = this._createValueCell(totalValue + ' ' + i18n('LABEL_SUMMARY_OF') + ' ' + totalDays);
        footer.append(this._createRow(titleCell, valueCell));
        locationList.append(footer);
    },

    _createRow: function(titleCell, valueCell) {
        var row = $('<li />');
        row.append(titleCell);
        row.append(valueCell);
        return row;
    },

    _createTitleCell: function(content, activityClass) {
        var cell = $('<span />').addClass('first-column');
        var cellContent = $('<span />').append(content).addClass('content');
        if (activityClass) {
            var color = $('<span/>').addClass(activityClass).addClass("color");
            cell.append(color);
        }
        cell.append(cellContent);
        return cell;
    },

    _createValueCell: function(content) {
        return $('<span />').append(content);
    },

    _appendHeader: function(locationList, headerText) {
        var header = $('<div class="header">');
        header.append(headerText);
        locationList.append(header);
    }
};
